<!--
To change this template, choose Tools | Templates
and open the template in the editor.
-->
<!DOCTYPE html>
<html>
<head>
<title>บันทึกข้อมูล</title>
</head>
<body>
    <br>
    <table width="150" border="0" align="center" cellspacing="0">
   
  <?  
    
$objConnect = mysql_connect("localhost","root","password") or die("Error Connect to Database");
$objDB = mysql_select_db("regisonline");

/*$sql2 = "SELECT max(regisid) FROM regis"; 
$resutl2 = mysql_query($sql2); 
$total_max2 = mysql_result($result2,0);
$nums2 = substr($total_max2,3,4) + 1; 
$id2 = str_pad($nums2,4,"0",STR_PAD_LEFT); */

/*$strSQL = "INSERT INTO regis ";
$strSQL .="(registypeid,registypeid) ";
$strSQL .="VALUES ";
$strSQL .="('".$_POST["type"]."','".$_POST["plan"]."') ";*/

if ($_POST['firstname'] != ""){
                     $countdata=count($_POST['lastname']);
                     for ($i=0;$i<$countdata;$i++) {
                         
$countdata=count($_POST['lastname']);
$firstname=$_POST["firstname"][$i];
$lastname=$_POST["lastname"][$i];
$citizenid=$_POST["citizenid"][$i];
$birthday=$_POST["birthday"][$i];
$nation=$_POST["nation"][$i];
$race=$_POST["race"][$i];
$religion=$_POST["religion"][$i];
$email=$_POST["email"][$i];                         
                         
                         
                  
$sql = "SELECT max(studyid) FROM study"; 
$result = mysql_query($sql); 
$total_max = mysql_result($result,0); 
$nums = $total_max + 1; 
$id = $nums; 

$strSQL = "INSERT INTO study "; 
$strSQL .="(studyid,firstname,lastname,citizenid,birthday,nation,race,religion,email,createdate,updatedate) ";
$strSQL .="VALUES ";
$strSQL .="('$id','$firstname','$lastname','$citizenid','$birthday','$nation','$race','$religion','$email',NOW(),NOW())";

/*$strSQL .="('$id','".$_POST["firstname"]."','".$_POST["lastname"]."','".$_POST["citizenid"]."' ";
$strSQL .=",'".$_POST["nation"]."','".$_POST["race"]."','".$_POST["religion"]."','".$_POST["email"]."') ";*/
$objQuery = mysql_query($strSQL);
        }
   }


if ($_POST['addresstype'] != ""){
                     $countdata=count($_POST['address']);
                     for ($i=0;$i<$countdata;$i++) {
                         
$countdata=count($_POST['address']);
$addresstype=$_POST["addresstype"][$i];
$address=$_POST["address"][$i];
$moo=$_POST["moo"][$i];
$village=$_POST["village"][$i];
$lane=$_POST["lane"][$i];
$road=$_POST["road"][$i];
$province=$_POST["province"][$i];
$district=$_POST["district"][$i];
$subdistrict=$_POST["subdistrict"][$i];
$postcode=$_POST["postcode"][$i];
$phone=$_POST["phone"][$i];
$mobile=$_POST["mobile"][$i];
  
$sql1 = "SELECT max(addressid) FROM address"; 
$result1 = mysql_query($sql1); 
$total_max1 = mysql_result($result1,0); 
$nums1 = $total_max1 + 1; 
$id1 = $nums1;

$strSQL = "INSERT INTO address ";
$strSQL .="(addressid,addresstype,address,moo,village,lane,road,province,district,subdistrict,postcode,phone,mobile,createdate,updatedate) ";
$strSQL .="VALUES ";
$strSQL .="('$id1','$addresstype','$address','$moo','$village','$lane','$road','$province','$district','$subdistrict','$postcode','$phone','$mobile',NOW(),NOW())";

/*$strSQL .="('$id1','".$_POST["addresstype"]."','".$_POST["address"]."','".$_POST["moo"]."' ";
$strSQL .=",'".$_POST["village"]."','".$_POST["lane"]."','".$_POST["road"]."','".$_POST["province"]."' ";
$strSQL .=",'".$_POST["district"]."','".$_POST["subdistrict"]."','".$_POST["postcode"]."','".$_POST["phone"]."','".$_POST["mobile"]."',NOW(),NOW()) ";*/
$objQuery = mysql_query($strSQL);
           }
        }
        
if ($_POST['firstname'] != ""){
                     $countdata=count($_POST['lastname']);
                     for ($i=0;$i<$countdata;$i++) {
                         
$countdata=count($_POST['lastname']);
//$firstname=$_POST["firstname"][$i];
$fromschool=$_POST["fromschool"][$i];
$province1=$_POST["province1"][$i];
$subdistrict1=$_POST["subdistrict1"][$i];
$district1=$_POST["district1"][$i];

                  
$sql = "SELECT max(eduid) FROM education"; 
$result = mysql_query($sql); 
$total_max = mysql_result($result,0); 
$nums = $total_max + 1; 
$id = $nums;

$strSQL = "INSERT INTO education "; 
$strSQL .="(eduid,fromschool,province,subdistrict,district,createdate,updatedate) ";
$strSQL .="VALUES ";
$strSQL .="('$id','$fromschool','$province1','$subdistrict1','$district1',NOW(),NOW())";

/*$strSQL .="('$id','".$_POST["firstname"]."','".$_POST["lastname"]."','".$_POST["citizenid"]."' ";
$strSQL .=",'".$_POST["nation"]."','".$_POST["race"]."','".$_POST["religion"]."','".$_POST["email"]."') ";*/
$objQuery = mysql_query($strSQL);
        }
   }

   
if ($_POST['firstname'] != ""){
                     $countdata=count($_POST['lastname']);
                     for ($i=0;$i<$countdata;$i++) {
                         
$countdata=count($_POST['lastname']);
$firstname1=$_POST["firstname1"][$i];
$lastname1=$_POST["lastname1"][$i];
$occupation=$_POST["occupation"][$i];
$citizenid1=$_POST["citizenid1"][$i];
$phone1=$_POST["phone1"][$i];
$mobile1=$_POST["mobile1"][$i];
$relation=$_POST["relation"][$i];
  
$sql1 = "SELECT max(parentid) FROM parent"; 
$result1 = mysql_query($sql1); 
$total_max1 = mysql_result($result1,0); 
$nums1 = $total_max1 + 1; 
$id1 = $nums1;

$strSQL = "INSERT INTO parent ";
$strSQL .="(parentid,relation,firstname,lastname,occupation,citizenid,phone,mobile,createdate,updatedate) ";
$strSQL .="VALUES ";
$strSQL .="('$id1','$relation','$firstname1','$lastname1','$occupation','$citizenid1','$phone1','$mobile1',NOW(),NOW())";

/*$strSQL .="('$id1','".$_POST["addresstype"]."','".$_POST["address"]."','".$_POST["moo"]."' ";
$strSQL .=",'".$_POST["village"]."','".$_POST["lane"]."','".$_POST["road"]."','".$_POST["province"]."' ";
$strSQL .=",'".$_POST["district"]."','".$_POST["subdistrict"]."','".$_POST["postcode"]."','".$_POST["phone"]."','".$_POST["mobile"]."',NOW(),NOW()) ";*/
$objQuery = mysql_query($strSQL);
           }
        }
        
if ($_POST['firstname'] != ""){
                     $countdata=count($_POST['lastname']);
                     for ($i=0;$i<$countdata;$i++) {
                         
$countdata=count($_POST['lastname']);
$firstname2=$_POST["firstname2"][$i];
$lastname2=$_POST["lastname2"][$i];
$occupation1=$_POST["occupation1"][$i];
$citizenid2=$_POST["citizenid2"][$i];
$phone2=$_POST["phone2"][$i];
$mobile2=$_POST["mobile2"][$i];

$sql1 = "SELECT max(hostid) FROM host"; 
$result1 = mysql_query($sql1); 
$total_max1 = mysql_result($result1,0); 
$nums1 = $total_max1 + 1; 
$id1 = $nums1;

$strSQL = "INSERT INTO host ";
$strSQL .="(hostid,firstname,lastname,occupation,citizenid,phone,mobile,createdate,updatedate) ";
$strSQL .="VALUES ";
$strSQL .="('$id1','$firstname2','$lastname2','$occupation1','$citizenid2','$phone2','$mobile2',NOW(),NOW())";

/*$strSQL .="('$id1','".$_POST["addresstype"]."','".$_POST["address"]."','".$_POST["moo"]."' ";
$strSQL .=",'".$_POST["village"]."','".$_POST["lane"]."','".$_POST["road"]."','".$_POST["province"]."' ";
$strSQL .=",'".$_POST["district"]."','".$_POST["subdistrict"]."','".$_POST["postcode"]."','".$_POST["phone"]."','".$_POST["mobile"]."',NOW(),NOW()) ";*/
$objQuery = mysql_query($strSQL);
           }
        }
        
if ($_POST['firstname'] != ""){
                     $countdata=count($_POST['lastname']);
                     for ($i=0;$i<$countdata;$i++) {
                         
$countdata=count($_POST['lastname']);
  
$sql7 = "SELECT regisid FROM regis ORDER BY regisdate desc LIMIT 1"; 
$result7 = mysql_query($sql7); 
$total_max7 = mysql_result($result7,0); 
$nums7 = $total_max7 + 1; 
$id7 = $nums7;

$sql2 = "SELECT max(studyid) FROM study"; 
$result2 = mysql_query($sql2); 
$total_max2 = mysql_result($result2,0); 
$id2 = $total_max; 
//$id2 = str_pad($nums2,4,"0",STR_PAD);

$sql3 = "SELECT max(addressid) FROM address"; 
$result3 = mysql_query($sql3); 
$total_max3 = mysql_result($result3,0); 
$id3 = $total_max3 ; 
//$id3 = str_pad($nums3,4,"0",STR_PAD);

$sql4 = "SELECT max(eduid) FROM education"; 
$result4 = mysql_query($sql4); 
$total_max4 = mysql_result($result4,0); 
$id4 = $total_max4 ; 
//$id4 = str_pad($nums4,4,"0",STR_PAD);

$sql5 = "SELECT max(parentid) FROM parent"; 
$result5 = mysql_query($sql5); 
$total_max5 = mysql_result($result5,0); 
$id5 = $total_max5 ; 
//$id5 = str_pad($nums5,4,"0",STR_PAD);

$sql6 = "SELECT max(hostid) FROM host"; 
$result6 = mysql_query($sql6); 
$total_max6 = mysql_result($result6,0); 
$id6 = $total_max6 ; 
//$id6 = str_pad($nums6,4,"0",STR_PAD);


$strSQL = "INSERT INTO regis ";
$strSQL .="(regisid,registypeid,regisplanid,regisdate,studyid,censusaddressid,currentaddressid,eduid,fatherid,motherid,hostid,eduyear) ";
$strSQL .="VALUES ";
$strSQL .="('$id7','".$_POST["type"]."','".$_POST["plan"]."',NOW(),'$id2','$id3','$id3','$id4','$id5','$id5','$id6','2555')";

/*$strSQL .="('$id1','".$_POST["addresstype"]."','".$_POST["address"]."','".$_POST["moo"]."' ";
$strSQL .=",'".$_POST["village"]."','".$_POST["lane"]."','".$_POST["road"]."','".$_POST["province"]."' ";
$strSQL .=",'".$_POST["district"]."','".$_POST["subdistrict"]."','".$_POST["postcode"]."','".$_POST["phone"]."','".$_POST["mobile"]."',NOW(),NOW()) ";*/
$objQuery = mysql_query($strSQL);
           }    
        }

if($objQuery)
{
    
	echo "<font color='#ff0000'><b>&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbspบันทึกข้อมูลเรียบร้อย<b></font>";
                echo "<br>&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbspเลขที่สมัครคือ: ".$id7;
}
else
{
	echo "Error Save [".$strSQL."]";
}
mysql_close($objConnect);
            

?>
        
    <tr><td colspan="2">
      <div align="center"><a href="/regisonline/template?phppage=adminedit.php&editPrt"> <img src="/regisonline/resources/images/gif/gif1.bmp" width="400" height="40"  ></a></div></td></tr>
    <br><br><tr><td><br></td></tr>
    <tr><td colspan="2">
      <div align="center"><a href="/regisonline/template?phppage=adminedit.php&searchPrt"> <img src="/regisonline/resources/images/gif/gif6.bmp" width="200" height="40"  ></a></div></td></tr>       
        
 </table>
</body>
</html>